package humanMirror.model.human;

/**
 * Class SomeConstants is used for storing some public constants.
 *
 * @author Anton Samarsky
 * @version 1.11 25 jul 2012
 */
public class SomeConstants {

    public enum Organs {
        BRAIN((byte) 0), LIVER((byte) 1);

        Organs(byte organNumber) {
            this.organNumber = organNumber;
        }

        private byte organNumber;

        public byte getOrganNumber() {
            return this.organNumber;
        }

        public static SomeConstants.Organs numberToOrgan(int organId) {
            SomeConstants.Organs organ;
            switch (organId) {
                case 0:
                    organ = SomeConstants.Organs.BRAIN;
                    break;
                case 1:
                    organ = SomeConstants.Organs.LIVER;
                    break;
                default:
                    organ = SomeConstants.Organs.BRAIN;
            }
            return organ;
        }
    }

    public enum Parameters {
        HEALTH(0), ENERGY(1, Organs.BRAIN), MEMORY(2, Organs.BRAIN), OXYGENATION(3, Organs.BRAIN),
        DETOXIFICATION(1, Organs.LIVER), GLUCOSE(2, Organs.LIVER), CHOLESTEROL(3, Organs.LIVER);

        private int parameterNumber;
        private Organs organ = null;

        Parameters(int parameterNumber, Organs organ) {
            this.parameterNumber = parameterNumber;
            this.organ = organ;
        }

        Parameters(int parameterNumber) {
            this.parameterNumber = parameterNumber;
        }

        public static Parameters[] getOrganParameters(Organs organ) {
            Parameters[] parameters = new Parameters[MAX_COUNT_OF_PARAMS];
            parameters[0] = Parameters.HEALTH;
            int i = 1;
            for (Parameters parameter : Parameters.values()) {
                if (parameter.getOrgan() != null) {
                    if (parameter.getOrgan().toString().equals(organ.toString())) {
                        parameters[i] = parameter;
                        i += 1;
                    }
                }
                if (i == MAX_COUNT_OF_PARAMS) {
                    break;
                }
            }
            return parameters;
        }

        public Parameters getOrganParameter(Organs organ, int parameterNumber) {
            Parameters[] parameters = getOrganParameters(organ);
            return searchParameter(parameterNumber, parameters);
        }

        /**
         * @param parameters      has to contain just parameters of certain organ
         * @param parameterNumber number of parameter to be shown
         * @return parameter of certain organ with given index
         */
        public static Parameters getOrganParameter(Parameters[] parameters, int parameterNumber) {
            return searchParameter(parameterNumber, parameters);
        }

        public static String getParameterString(Parameters parameter) {
            return parameter.toString();
        }

        private static Parameters searchParameter(int parameterNumber, Parameters[] parameters) {
            for (Parameters parameter : parameters) {
                if (parameter.getParameterNumber() == parameterNumber) {
                    return parameter;
                }
            }
            return null;
        }

        public int getParameterNumber() {
            return parameterNumber;
        }

        public Organs getOrgan() {
            return organ;
        }
    }

    public static final byte COUNT_OF_ORGANS = 2;
    public static final byte MAX_COUNT_OF_PARAMS = 4;
    //   public static final byte HEALTH = 0;

    //-----------------------------------//
    //public static final byte BRAIN = 0;
//    public static final byte ENERGY = 1;
//    public static final byte MEMORY = 2;
//    public static final byte OXYGENATION = 3;
//    public static final byte BRAIN_COUNT_OF_PARAMS = 4;

    //-----------------------------------//
    //  public static final byte LIVER = 1;

    //    public static final byte DETOXIFICATION = 1;
//    public static final byte GLUCOSE = 2;
//    public static final byte CHOLESTEROL = 3;
    public static final byte LIVER_COUNT_OF_PARAMS = 4;
}